package pub.xspace.nova.system.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import cn.hutool.core.util.ObjectUtil;
import jakarta.annotation.Resource;
import pub.xspace.nova.system.domain.SysOrg;
import pub.xspace.nova.system.mapper.SysOrgMapper;
import pub.xspace.nova.system.service.SysOrgService;

/**
 * 组织机构管理 Service实现类
 *
 * @author HeJianrong
 */
@Service
public class SysOrgServiceImpl implements SysOrgService {

	@Resource
	private SysOrgMapper sysOrgMapper;
	
	@Override
	public SysOrg getById(String id) {
		return sysOrgMapper.selectById(id);
	}

	@Override
	public List<SysOrg> getByParams(SysOrg sysOrg) {
		return sysOrgMapper.selectByParams(sysOrg);
	}
	
	@Override
	public List<SysOrg> getTreeData(){
		String pid = "-1";
		
		return createTreeList(pid);
	}
	
	private List<SysOrg> createTreeList(String pid){
		SysOrg sysOrg = new SysOrg();
		sysOrg.setPid(pid);
		List<SysOrg> orgs = sysOrgMapper.selectByParams(sysOrg);
		if(ObjectUtil.isNotEmpty(orgs)) {
			for(SysOrg org :orgs) {
				org.setChildren(createTreeList(org.getId()));
			}
		}
		return orgs;
	}

	@Override
	public int save(SysOrg sysOrg) {
		return sysOrgMapper.insert(sysOrg);
	}

	@Override
	public int updateById(SysOrg sysOrg) {
		return sysOrgMapper.updateById(sysOrg);
	}

	@Override
	public int deleteById(String id) {
		return sysOrgMapper.deleteById(id);
	}

	@Override
	public int deleteByIds(List<String> ids) {
		return sysOrgMapper.deleteByIds(ids);
	}

	
	
}
